<template>
<span>id</span>
   <el-input
    v-model="activity.id"
    style="width: 240px"
    disabled
  />
  <br/>
  <span>负责人</span>
   <el-input
    v-model="activity.ownerName"
    style="width: 240px"
    disabled
  
  />
  <br/>
  <span>活动名称</span>
   <el-input
    v-model="activity.name"
    style="width: 240px"
    disabled
  
  />
  <br/>
  <span>开始时间</span>
   <el-input
    v-model="activity.startTime"
    style="width: 240px"
    disabled
   
  />
  <br/>
  <span>结束时间</span>
   <el-input
    v-model="activity.endTime"
    style="width: 240px"
    disabled
   
  />
  <br/>
  <span>活动预算</span>
   <el-input
    v-model="activity.cost"
    style="width: 240px"
    disabled
   
  />
  <br/>
  <span>活动描述</span>
   <el-input
    v-model="activity.description"
    style="width: 240px"
    disabled
    
  />
  <br/>
  <span>创建时间</span>
   <el-input
    v-model="activity.createTime"
    style="width: 240px"
    disabled
    
  />
  <br/>
  <span>创建人</span>
   <el-input
    v-model="activity.createName"
    style="width: 240px"
    disabled
    
  />
  <br/>
  <span>编辑时间</span>
   <el-input
    v-model="activity.editTime"
    style="width: 240px"
    disabled
   
  />
  <br/>
  <span>编辑人</span>
   <el-input
    v-model="activity.editName"
    style="width: 240px"
    disabled
  />
  <br/>
  <br/>
  <span>填写备注</span>
   <el-input
    v-model="TActivityRemarkQuery.noteContent"
    style="width: 500px"
    :rows="5"
    type="textarea"
  />
  <br/>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="序号" width="180" />
    <el-table-column prop="noteContent" label="备注内容" width="180" />
    <el-table-column prop="createTime" label="备注时间"width="180" />
    <el-table-column prop="createName" label="备注人"width="180" />
    <el-table-column prop="editTime" label="编辑时间"width="180" />
    <el-table-column prop="editName" label="编辑人"width="180" />
    <el-table-column label="操作"width="180" >
        <template #default="scoped">
        <el-button link type="primary" size="small" @click="edit(scoped.row)">编辑</el-button>
        <el-button link type="primary" size="small" @click="del(scoped.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination background layout="prev, pager, next" :total="total" :page-size="pagesize" @current-change="change"/>
  <el-button type="primary" @click="submit">提交</el-button>
  <el-button type="primary" @click="back">返回</el-button>
  <el-dialog v-model="dialogFormVisible" title="更改备注" width="500">
    <el-input
    v-model="editValue.noteContent"
    :rows="5"
    type="textarea"
  />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit_edit">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { doDelete, doGet, doPost } from '@/util/axios';
import { notify } from '@/util/notification';
import { onMounted, ref } from 'vue';
import { useRouter,useRoute } from 'vue-router';
let router=useRouter()
let route=useRoute()
let activity=ref({})
let TActivityRemarkQuery=ref({})
let editValue=ref({})
let tableData=ref([])
let current=ref(1)
const pagesize=2
let total=ref(0)
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'
onMounted(()=>{
    getActivityDetail(route.params.id)
    getList(current.value)
})
function getActivityDetail(id){
    doGet("/getActivityDetail/"+id).then(res=>{
        if(res.data.code==200){
            activity.value=res.data.data
        }
    })
}
function back(){
  router.back()
}
function submit(){
    TActivityRemarkQuery.value["activityId"]=route.params.id
    doPost("/saveTActivityRemark",TActivityRemarkQuery.value).then(res=>{
        if(res.data.code==200){
           notify("添加成功","success")
           TActivityRemarkQuery.value={}
           change(current.value)
        }else{
            notify("添加失败","error")
        }
    })
}
function change(num){
    getList(num)
}
function getList(num){
  doGet("/getTActivityRemark",{"current":num,"pagesize":pagesize,"id":route.params.id}).then(res=>{
    tableData.value=res.data.data.list
    console.log(res)
    current.value=res.data.data.pageNum
    total.value=res.data.data.total
  })
}
function edit(obj){
    dialogFormVisible.value=true
    editValue.value["noteContent"]=obj.noteContent
    editValue.value["id"]=obj.id
}
function cancel(){
    dialogFormVisible.value=false
    editValue.value={}
}
function submit_edit(){
    doPost("/editTActivityRemark",editValue.value).then(res=>{
        if(res.data.code==200){
            notify("修改成功","success")
            cancel()
            change(current.value)
        }else{
            notify("修改失败","error")
        }
    })
}
function del(id){
    doDelete("/delTActivityRemark/"+id).then(res=>{
        if(res.data.code==200){
            notify("删除成功","success")
            change(current.value)
        }else{
            notify("删除失败","error")
        }
    })
}
</script>
<style scoped></style>